{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f14dd08e",
   "metadata": {},
   "source": [
    "---\n",
    "*时间：2022/10/31\n",
    "\n",
    "*课程：python\n",
    "\n",
    "*记录人：cm"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c153175b",
   "metadata": {},
   "source": [
    "本周知识点\n",
    "·元组 集合和字典的基本概念和常见的方法\n",
    "> 1.元组\n",
    "> 2.集合\n",
    "> 3.字典"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "704e496a",
   "metadata": {},
   "source": [
    "## 1.元组（tuple）\n",
    "> 1.概念\n",
    ">> 1.具有和序列数据相同的运算规则：取值和切片\n",
    "\n",
    ">> 2.表征：（12345,54321，‘hello’），用圆括号/小括号 括起来的，中间仍然使用逗号隔开的数据形态\n",
    "\n",
    ">> 3.性质：不可变性,没有什么增删改查的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "0bf0f8a2",
   "metadata": {},
   "outputs": [],
   "source": [
    "product = (\"Head First Python\",88) # 创建了一个元组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "821b5b3d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('Head First Python', 88) <class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "print(product,type(product))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f9201072",
   "metadata": {},
   "source": [
    "# 案例：\n",
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "0b9d9cbb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2022, tm_mon=10, tm_mday=31, tm_hour=10, tm_min=20, tm_sec=41, tm_wday=0, tm_yday=304, tm_isdst=0)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "f92e8172",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1667182887.4342191"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.time()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bbd7f1bb",
   "metadata": {},
   "outputs": [],
   "source": [
    "product.count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "17943081",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1800001, 1800002, 1800003)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_seq = 1800001,1800002,1800003\n",
    "name_seq"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "352d4b4e",
   "metadata": {},
   "source": [
    "## 2. 集合（Sets)\n",
    "> 1.集合的概念\n",
    "\n",
    ">> 1. 没有重复元素的一个数据结构\n",
    "\n",
    ">> 2. 形态：{'apple'，'orange','apple','pear','orange','banana'}\n",
    "\n",
    "> 2.集合的运算\n",
    "\n",
    ">> 1.交集运算： & , intersection\n",
    "\n",
    ">> 2.并集运算：|, union"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "af68ecc9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'banana', 'pear', 'apple', 'orange'} <class 'set'>\n"
     ]
    }
   ],
   "source": [
    "basket = {'apple','orange','apple','pear','orange','banana'}\n",
    "print(basket,type(basket))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "e1da33cf",
   "metadata": {},
   "outputs": [],
   "source": [
    "舞蹈社 = {180001,180003,180004,180005,180007}\n",
    "合唱团 = {180009,181111,180004,180001}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "4d3d99e3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(舞蹈社)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "5a8f7b0f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(合唱团)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "85737803",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 交集运算和并集运算的实践"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "66f3d2c1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{180001, 180004}\n",
      "{180001, 180004}\n"
     ]
    }
   ],
   "source": [
    "# 交集：\n",
    "print(舞蹈社 & 合唱团)\n",
    "print(舞蹈社.intersection(合唱团))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "b188a809",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{180001, 180003, 180004, 180005, 180007, 180009, 181111}\n",
      "7\n",
      "{180001, 180003, 180004, 180005, 180007, 180009, 181111}\n",
      "7\n"
     ]
    }
   ],
   "source": [
    "# 并集：统计数量\n",
    "print(舞蹈社 | 合唱团)\n",
    "print(len(舞蹈社 | 合唱团))\n",
    "\n",
    "print(舞蹈社.union(合唱团))\n",
    "print(len(舞蹈社.union(合唱团)))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a83062d3",
   "metadata": {},
   "source": [
    "## 3.字典(dict)\n",
    "> 1.基本的概念\n",
    ">> 1.mapping types:映射类型\n",
    "    \n",
    ">> 2.key:values,键:值 对\n",
    "        \n",
    ">> 3.字典的性质\n",
    "\n",
    ">>> 1.无序性\n",
    ">>> 2.key不可变性\n",
    ">>> 3.key唯一性\n",
    "\n",
    "> 2.字典的创建\n",
    "\n",
    "> 3.常用的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "2a800842",
   "metadata": {},
   "outputs": [],
   "source": [
    "product_dict = {\n",
    "    \"A\":6,\n",
    "    \"B\":10,\n",
    "    \"C\":12,\n",
    "    \"D\":8\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "9c67335a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'A': 6, 'B': 10, 'C': 12, 'D': 8} <class 'dict'>\n"
     ]
    }
   ],
   "source": [
    "print(product_dict,type(product_dict))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "38c58125",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "product_dict[\"A\"] #"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "66f89a5b",
   "metadata": {},
   "outputs": [],
   "source": [
    "user_info = {\n",
    "    \"bgwdfflruei4839\":[\"Zhichao\",\"IT\",\"广州\",\"广州南方学院\"]\n",
    "    }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "3e9b756d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Zhichao', 'IT', '广州', '广州南方学院']"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user_info[\"bgwdfflruei4839\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e285e4e5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
